package com.jiutong.meipengdai.http.present;

import android.content.Context;

import com.jiutong.meipengdai.entity.BaseRespond;
import com.jiutong.meipengdai.entity.EvaluateRespond;
import com.jiutong.meipengdai.http.model.interfaces.LoanApplyBiz;
import com.jiutong.meipengdai.http.model.interfaces.LoanRelaBize;
import com.jiutong.meipengdai.http.model.requests.LoanApplyRequest;
import com.jiutong.meipengdai.http.model.requests.LoanRelaRequest;
import com.jiutong.meipengdai.http.subscribers.ProgressSubscriber;
import com.jiutong.meipengdai.http.subscribers.SubscriberOnNextListener;

import java.util.HashMap;

/**
 * 贷款相关请求
 * Created by suxi on 2017/5/31.
 */

public class LoanApplyPresent {

    private final Context mContext;
    private final LoanApplyBiz mBaseBiz;
    private final LoanApplyRequest request;

    public LoanApplyPresent(Context context, LoanApplyBiz baseBiz){
        this.mContext = context;
        this.mBaseBiz = baseBiz;
        request = new LoanApplyRequest();
    }


    /**
     * 贷款申请
     */
    public void loanApply(){
        SubscriberOnNextListener onNextListener = new SubscriberOnNextListener<BaseRespond>() {
            @Override
            public void onNext(BaseRespond subjects) {
                mBaseBiz.onSuccess(subjects);
            }

            @Override
            public void onError(Throwable e) {
                mBaseBiz.onError(e);
            }
        };

        HashMap<String, Object> fieldsMap = new HashMap<>();
        fieldsMap.put("houseId", mBaseBiz.getHouseId());
        fieldsMap.put("applyAmount", mBaseBiz.getApplyAmount());
        fieldsMap.put("time", mBaseBiz.getTime());
        fieldsMap.put("unit", mBaseBiz.getUnit());
        request.loanApply(new ProgressSubscriber(onNextListener, mContext), fieldsMap);
    }


}
